package com.tools.ad.adscene;

import android.support.annotation.Keep;

import com.hm.base.android.mob.AMApplication;
import com.tools.ad.AdType;
import com.tools.ad.EntranceType;
import com.tools.ad.util.GARecordUtils;

/**
 * desc: 主要用来上报广告信息的scene
 * date: 2018/4/24
 * author: ancun
 */

public abstract class AdReportScene extends AdStrategyScene {

    private boolean report = true;
    protected boolean repeatRequestForActivity = false;

    @Keep
    public AdReportScene(AMApplication context, EntranceType entranceType) {
        super(context, entranceType);
    }

    @Override
    protected void onADClick(AdType adType) {
        if (isReport()) {
            GARecordUtils.onADClick(imContext, getFormatEntranceNameByRawAd(), adType);
        }
    }

    @Override
    protected void onADShow(AdType adType) {
        if (isReport()) {
            GARecordUtils.onADShowEffective(imContext, mEntranceType.getName());
            GARecordUtils.onADShow(imContext, getFormatEntranceNameByRawAd(), adType);
        }
    }

    @Override
    protected void onADLoad(AdType adType) {
        if (repeatRequestForActivity) {
            if (isReport()) {
                GARecordUtils.onADLoadByActivity(imContext, getFormatEntranceNameByRawAd(), adType);
            }
        } else {
            if (isReport()) {
                GARecordUtils.onADLoad(imContext, mEntranceType.getName(), adType);
            }
        }
    }

    @Override
    protected void onADFail(AdType adType, int code) {
        if (isReport()) {
            GARecordUtils.onADFail(imContext, getFormatEntranceNameByRawAd(), adType, code);
        }
    }

    @Override
    protected void onADFilled(AdType adType) {
        if (isReport()) {
            GARecordUtils.onADFilled(imContext, getFormatEntranceNameByRawAd(), adType);
        }
    }

    @Override
    protected void onRequestAll() {
        super.onRequestAll();
        if (!repeatRequestForActivity && isReport()) {
            GARecordUtils.onRequestEffective(imContext, mEntranceType.getName());
        }
    }

    public boolean isReport() {
        return report;
    }

    public void setReport(boolean report) {
        this.report = report;
    }

    public void setRepeatRequestForActivity(boolean repeatRequestForActivity) {
        this.repeatRequestForActivity = repeatRequestForActivity;
    }
}
